import {UserActions} from './user';

const initialState = {
  total: 0,
  count: 1,
  current: 1,
  results: [],
};

export const SupplierListActions = {
  SUPPLIER_LIST_UPDATE: 'supplier_list_update',
  SUPPLIER_LIST_RESET: 'supplier_list_reset',
};

export function updateSupplierList(payload) {
  return {
    type: SupplierListActions.SUPPLIER_LIST_UPDATE,
    payload,
  };
}

export function resetSupplierList(payload) {
  return {
    type: SupplierListActions.SUPPLIER_LIST_RESET,
    payload,
  };
}

export default function supplierList(state = initialState, action) {
  switch (action.type) {
    case SupplierListActions.SUPPLIER_LIST_UPDATE:
      return {...state, ...action.payload};
    case SupplierListActions.SUPPLIER_LIST_RESET:
      return initialState;
    case UserActions.USER_SIGN_OUT:
      return {
        total: 0,
        count: 1,
        current: 1,
        results: [],
      };
    default:
      return state;
  }
}
